#
# Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
#
# -*- mode: python; -*-

Import('BuildEnv')
import os

env = BuildEnv.Clone()
env.Append(CPPPATH = env['TOP'])
env.Append(CPPPATH = [env['TOP'] + '/config-client-mgr'])
env.Append(CPPPATH = [env['TOP'] + '/base/sandesh'])
env.Append(CPPPATH = [env['TOP'] + '/database'])

etcd_incl = os.environ.get('CONTRAIL_ETCD_INCL');

if etcd_incl:
    env.Append(CXXFLAGS = '-Wall -DCONTRAIL_ETCD_INCL -std=c++11')
    env.Prepend(LIBS=['etcdql'])

env.Prepend(LIBS=['io', 'base', 'cassandra_cql', 'cassandra', 'gendb', 'SimpleAmqpClient'])

SandeshGenFiles = env.SandeshGenCpp('config_client_log.sandesh')
SandeshGenFiles += env.SandeshGenCpp('config_client_show.sandesh')
SandeshGenSrcs = env.ExtractCpp(SandeshGenFiles)

except_env = BuildEnv.Clone()
except_env.Append(CPPPATH = [env['TOP'] + '/config-client-mgr'])
except_env.Append(CPPPATH = [env['TOP'] + '/base/sandesh'])
except_env.CppEnableExceptions()
except_env.Append(CPPPATH = env['TOP'])

sandesh_objs = []
for src in SandeshGenSrcs:
    objname = src.replace('.cpp', '.o')
    obj = except_env.Object(objname, src)
    sandesh_objs.append(obj)

except_env = BuildEnv.Clone()
except_env.CppEnableExceptions()
except_env.Append(CPPPATH = env['TOP'])

if etcd_incl:
    libconfig_client_mgr = env.Library('config_client_mgr',
                         ['config_amqp_client.cc',
                          'config_cass2json_adapter.cc',
                          'config_cassandra_client.cc',
                          'config_etcd_client.cc',
                          'config_client_manager.cc',
                          'config_db_client.cc',
                          'config_factory.cc',
                          'config_client_log.cc',
                          'config_json_parser_base.cc',
                         ] + sandesh_objs)
else:
    libconfig_client_mgr = env.Library('config_client_mgr',
                         ['config_amqp_client.cc',
                          'config_cass2json_adapter.cc',
                          'config_cassandra_client.cc',
                          'config_client_manager.cc',
                          'config_db_client.cc',
                          'config_factory.cc',
                          'config_client_log.cc',
                          'config_json_parser_base.cc',
                         ] + sandesh_objs)

env.Requires(libconfig_client_mgr, '#build/lib/libSimpleAmqpClient.a')
env.Requires(libconfig_client_mgr, '#/build/include/rapidjson.h')
env.Install(env['TOP_LIB'], libconfig_client_mgr)

config_client_unit_tests = env.SConscript('test/SConscript', exports='BuildEnv',
                                   duplicate = 0)
Return('config_client_unit_tests')
